//1 引入
const mongoose = require('mongoose');
const {createHash} = require("crypto")
//2 连接
mongoose.connect('mongodb://localhost/f77',(err)=>{
    if(err){
        console.log(err);
        return;
    }
    console.log("数据库连接成功");
});
//3 创建数据结构
let userSchema = new mongoose.Schema({
    name:String,
    password:String
});
//4 建立数据模型 
let userModel = mongoose.model("userModel",userSchema,"users");
//操作数据库
//加密
/*let password = createHash("sha256")
               .update("abc123")
               .digest("hex")  */
/*                   
let res = userModel.create({
    name:"jack",
    password
});
res.then((data)=>{
   console.log(data)
}) */

 let res2 = userModel.find(
    {name:"jack",
    password:createHash("sha256")
            .update("234567")
            .digest("hex") });
res2.then((data)=>{
    console.log(data)
 }) 

 /* let res3=userModel.updateOne({_id:"6183398037eb5e512230d4ba"},
{
    password:createHash("sha256")
    .update("234567")
    .digest("hex") }
)
res3.then((data)=>{
    console.log(data)
}) */

